{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch"
   ]
  },
  {
   "cell_type": "markdown",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### 1. Sum Fusion"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "f_image\ntorch.Size([4, 5, 5])\nf_video\ntorch.Size([4, 5, 5])\noutput\ntorch.Size([4, 5, 5])\n"
    }
   ],
   "source": [
    "f_image = torch.randn(4,5,5)\n",
    "f_video = torch.randn(4,5,5)\n",
    "print(\"f_image\")\n",
    "print(f_image.shape)\n",
    "print(\"f_video\")\n",
    "print(f_video.shape)\n",
    "output = torch.add(f_image, f_video)\n",
    "print(\"output\")\n",
    "print(output.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### 2. Max Fusion"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "f_image\ntorch.Size([4, 5, 5])\nf_video\ntorch.Size([4, 5, 5])\noutput\ntorch.Size([4, 5, 5])\n"
    }
   ],
   "source": [
    "f_image = torch.randn(4,5,5)\n",
    "f_video = torch.randn(4,5,5)\n",
    "print(\"f_image\")\n",
    "print(f_image.shape)\n",
    "print(\"f_video\")\n",
    "print(f_video.shape)\n",
    "output = torch.max(f_image,f_video)\n",
    "print(\"output\")\n",
    "print(output.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### 3. Concatenation Fusion "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "torch.Size([8, 5, 5])\n"
    }
   ],
   "source": [
    "f_image = torch.randn(4,5,5)\n",
    "f_video = torch.randn(4,5,5)\n",
    "output = torch.cat([f_image, f_video], dim=0)\n",
    "print(output.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### 4. Conv Fusion "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "torch.Size([1, 4, 5, 5])\n"
    }
   ],
   "source": [
    "f_image = torch.randn(4,5,5)\n",
    "f_video = torch.randn(4,5,5)\n",
    "f_con = torch.cat([f_image, f_video], dim=0)\n",
    "f_con = f_con.view(1,8,5,5)\n",
    "weight = torch.randn(4,8,1,1)\n",
    "bias = torch.randn(4)\n",
    "output = torch.nn.functional.conv2d(f_con,weight,bias)\n",
    "print(output.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### 5. Bilinear Fusion"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": "tensor([[ 3.3315,  1.9532, -0.0806, -1.8231],\n        [ 6.1601, -1.6612,  2.3583, -2.3659],\n        [-2.3632,  3.7347,  8.7793,  0.8843],\n        [-1.9722, -2.7934, -9.0856,  7.4048]])\n"
    }
   ],
   "source": [
    "f_image = torch.randn(4,5,5)\n",
    "f_video = torch.randn(4,5,5)\n",
    "output =  f_image.view((4,5*5)).mm(f_video.view(4,5*5).permute(1,0))\n",
    "\n",
    "print(output)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3-final"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}